/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scanner;

import java.io.IOException;
import java.io.StringReader;

/**
 *
 * @author Maxim
 */
class CharacterStream {

    private StringReader stream;
    private int row;
    private int col;

    public CharacterStream(String filename){
        stream = new StringReader(filename);
        col = 0;
        row = 0;
    }

    public int read() throws IOException, Exception {
        int v = stream.read();
        if (v != -1) {
            if (v == 13) {
                stream.read();
                row++;
                col = 0;
            } else {
                col++;
            }
        }
        if (v >= 128) {
            throw new Exception("Unexpected symbol '" + (char) v + "'.");
        }
        return v;
    }

    public int getCol() {
        return col;
    }

    public int getRow() {
        return row;
    }
}
